var vueApp = new Vue({
  el: '#app',
  data: function () {
    return {
   	  	  list:[],
    	  currentPageNbr: config.currentPageNbr,
          pageSizes: config.pageSizes,
          pageSize: config.defaultpageSize,
          totalRecords: 0,
          editurl:'importtableinfo.html'
      };
  },
  mounted: function () {
    this.initData();

  },
  methods: {
    initData:function(){
       this.onSearch();       
    },
    shorten:function(txt){
    	var result=txt;
    	if(result.length>20){
    		return result.substr(0,20)+"...";
    	}
    	return result;
    },
    download:function(row){
    	var tmps = row.template_url.split("\.");
    	var filename = row.table_desc+"."+ tmps[tmps.length-1];
		var filepath = row.template_url;    
		var form="<form id='download' action='../../pub/attach/download' method='post'>";
		form +="<input type='hidden' name='filename'  value='"+filename+"' />";
		form +="<input type='hidden' name='filepath'  value='"+filepath+"' />";
		form +="</form>";
		$("#tableList").append(form);
		$("#download").submit();
		$("#download").remove();
    },
    add:function(){
    	location.href = this.editurl;
    },
    edit:function(row){
    	location.href = this.editurl+"?tableId="+row.table_id;
    },
    
    del:function(row){
    	var that =this;
    	that.$confirm('是否确认删除配置表 '+row.table_name+' ?', '提示', {
             confirmButtonText: '确定',
             cancelButtonText: '取消',
             type: 'warning'
        }).then(() => {
        	var reqData={
        		"tableId": row.table_id		
    	    };
        	tools.ajaxRequestAsyncEx("pub/import/deltable", reqData, function(data){
    	   		if (data.respCode != 0) {
    	   			that.showError(data.respDesc);    
    	   			return false;
    	   		}else{
    	   			that.$message({
    	                showClose: true,
    	                type: 'success',
    	                message: '删除成功!'
    	            });  
    	   			that.search();
    	   		}    	   			
    	    });
        	
        }).catch(() => {
           		return false;
        });
    },
   
    onSearch:function(){
      var that = this;
//      var jso = {
//      };
      var postdata = {
//    	  "jsonStr":JSON.stringify(jso),    		 
          "currentPageNbr" : this.currentPageNbr,
          "pageSize" : this.pageSize
      };
      
      tools.ajaxRequestAsyncEx("pub/import/tablelist",postdata, function(data){
          if (data.respCode == "0") {
        	  console.log(data);
              that.list = data.list;
              that.totalRecords = data.page.totalRecords;       
          } else {
              that.list = [];
              that.totalRecords =0;
              that.currentPageNbr=1;
              that.showError(data.respDesc);      
          }
      });
      

    },
    
    search:function(){
    	this.currentPageNbr = 1;
        this.onSearch();
    },
    handleSizeChange:function(pageSize){
        this.pageSize = pageSize;
        this.currentPageNbr = 1;
        this.onSearch();
    },

    handleCurrentChange:function(currentPageNbr){
      this.currentPageNbr = currentPageNbr;
      this.onSearch();
    },

    showError: function(info){
        var i = (info==undefined?"加载数据错误":info);
        this.$alert(i, '系统错误', {
             confirmButtonText: '确定'
        }); 
    },

  },
  watch:{
	  
  }
})